/*
 * Finals Calculator
 *
 * This file is part of Finals Calculator.
 * Finals Calculator is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * Finals Calculator is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Finals Calculator; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

/**
 * <p>The calculator window.</p>
 *
 * @author Cauchy Choi
 * @author Jonathan Chang
 */
public class CalculatorWindow extends javax.swing.JFrame
{
	/**
	 * Creates new form CalculatorWindow
	 */
	public CalculatorWindow()
	{
		initComponents();
		
		//Set final grade jTextFields to false to prevent user from inputting values.
		weightedFinalGradeTextField.setEditable(false);
		unweightedFinalGradeTextField.setEditable(false);
		
		//Set Standard Grading Scale radio buttons to be selected.
		weightedStandardGradingRadioButton.setSelected(true);
		unweightedStandardGradingRadioButton.setSelected(true);
		
		//Set "Choose..." buttons to be grayed out.
		weightedCustomGradingButton.setEnabled(false);
		unweightedCustomGradingButton.setEnabled(false);
		
		//Choose has not been clicked before.
		weightedChooseClicked = false;
		unweightedChooseClicked = false;
	}
	
	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
      // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
      private void initComponents()
      {
            weightedGradingButtonGroup = new javax.swing.ButtonGroup();
            unweightedGradingButtonGroup = new javax.swing.ButtonGroup();
            jTabbedPane1 = new javax.swing.JTabbedPane();
            weightedPanel = new javax.swing.JPanel();
            weightedCurrentGradeLabel = new javax.swing.JLabel();
            weightedFinalWorthLabel = new javax.swing.JLabel();
            weightedDesiredGradeLabel = new javax.swing.JLabel();
            weightedRoundLabel = new javax.swing.JLabel();
            weightedFinalGradeLabel = new javax.swing.JLabel();
            weightedCurrentGradeTextField = new javax.swing.JTextField();
            weightedFinalWorthTextField = new javax.swing.JTextField();
            weightedDesiredGradeTextField = new javax.swing.JTextField();
            weightedRoundTextField = new javax.swing.JTextField();
            weightedFinalGradeTextField = new javax.swing.JTextField();
            weightedCalculateButton = new javax.swing.JButton();
            weightedClearButton = new javax.swing.JButton();
            weightedExitButton = new javax.swing.JButton();
            weightedStandardGradingRadioButton = new javax.swing.JRadioButton();
            weightedCustomGradingRadioButton = new javax.swing.JRadioButton();
            weightedCustomGradingButton = new javax.swing.JButton();
            weightedCurrentGradePercentLabel = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            unweightedPanel = new javax.swing.JPanel();
            unweightedCurrentGradeLabel = new javax.swing.JLabel();
            unweightedCoursePointsLabel = new javax.swing.JLabel();
            unweightedFinalWorthLabel = new javax.swing.JLabel();
            unweightedDesiredGradeLabel = new javax.swing.JLabel();
            unweightedRoundLabel = new javax.swing.JLabel();
            unweightedFinalGradeLabel = new javax.swing.JLabel();
            unweightedCurrentGradeTextField = new javax.swing.JTextField();
            unweightedCoursePointsTextField = new javax.swing.JTextField();
            unweightedFinalWorthTextField = new javax.swing.JTextField();
            unweightedDesiredGradeTextField = new javax.swing.JTextField();
            unweightedRoundTextField = new javax.swing.JTextField();
            unweightedFinalGradeTextField = new javax.swing.JTextField();
            unweightedCalculateButton = new javax.swing.JButton();
            unweightedClearButton = new javax.swing.JButton();
            unweightedExitButton = new javax.swing.JButton();
            unweightedStandardGradingRadioButton = new javax.swing.JRadioButton();
            unweightedCustomGradingRadioButton = new javax.swing.JRadioButton();
            unweightedCustomGradingButton = new javax.swing.JButton();
            aboutPanel = new javax.swing.JPanel();
            aboutLabel = new javax.swing.JLabel();
            aboutExitButton = new javax.swing.JButton();

            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            weightedCurrentGradeLabel.setText("Current Grade in Course:");

            weightedFinalWorthLabel.setText("Weight of Final:");

            weightedDesiredGradeLabel.setText("Desired Letter Grade in the Course:");

            weightedRoundLabel.setText("Does the teacher round? (y/n):");

            weightedFinalGradeLabel.setText("Score on Final Needed:");

            weightedCalculateButton.setText("Calculate");
            weightedCalculateButton.addActionListener(new java.awt.event.ActionListener()
            {
                  public void actionPerformed(java.awt.event.ActionEvent evt)
                  {
                        weightedCalculateButtonActionPerformed(evt);
                  }
            });

            weightedClearButton.setText("Clear");
            weightedClearButton.addActionListener(new java.awt.event.ActionListener()
            {
                  public void actionPerformed(java.awt.event.ActionEvent evt)
                  {
                        weightedClearButtonActionPerformed(evt);
                  }
            });

            weightedExitButton.setText("Exit");
            weightedExitButton.addActionListener(new java.awt.event.ActionListener()
            {
                  public void actionPerformed(java.awt.event.ActionEvent evt)
                  {
                        weightedExitButtonActionPerformed(evt);
                  }
            });

            weightedGradingButtonGroup.add(weightedStandardGradingRadioButton);
            weightedStandardGradingRadioButton.setText("Standard Grading Scale");
            weightedStandardGradingRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
            weightedStandardGradingRadioButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
            weightedStandardGradingRadioButton.addActionListener(new java.awt.event.ActionListener()
            {
                  public void actionPerformed(java.awt.event.ActionEvent evt)
                  {
                        weightedStandardGradingRadioButtonActionPerformed(evt);
                  }
            });

            weightedGradingButtonGroup.add(weightedCustomGradingRadioButton);
            weightedCustomGradingRadioButton.setText("Custom Grading Scale");
            weightedCustomGradingRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
            weightedCustomGradingRadioButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
            weightedCustomGradingRadioButton.addActionListener(new java.awt.event.ActionListener()
            {
                  public void actionPerformed(java.awt.event.ActionEvent evt)
                  {
                        weightedCustomGradingRadioButtonActionPerformed(evt);
                  }
            });

            weightedCustomGradingButton.setText("Choose...");
            weightedCustomGradingButton.addActionListener(new java.awt.event.ActionListener()
            {
                  public void actionPerformed(java.awt.event.ActionEvent evt)
                  {
                        weightedCustomGradingButtonActionPerformed(evt);
                  }
            });

            weightedCurrentGradePercentLabel.setText("%");

            jLabel2.setText("%");

            org.jdesktop.layout.GroupLayout weightedPanelLayout = new org.jdesktop.layout.GroupLayout(weightedPanel);
            weightedPanel.setLayout(weightedPanelLayout);
            weightedPanelLayout.setHorizontalGroup(
                  weightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                  .add(org.jdesktop.layout.GroupLayout.TRAILING, weightedPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(weightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                              .add(weightedPanelLayout.createSequentialGroup()
                                    .add(weightedCalculateButton)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(weightedClearButton))
                              .add(weightedPanelLayout.createSequentialGroup()
                                    .add(weightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                          .add(weightedRoundLabel)
                                          .add(weightedCurrentGradeLabel)
                                          .add(weightedFinalWorthLabel)
                                          .add(weightedDesiredGradeLabel)
                                          .add(weightedStandardGradingRadioButton)
                                          .add(weightedCustomGradingRadioButton)
                                          .add(weightedFinalGradeLabel))
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(weightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                          .add(org.jdesktop.layout.GroupLayout.LEADING, weightedDesiredGradeTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
                                          .add(org.jdesktop.layout.GroupLayout.LEADING, weightedFinalWorthTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
                                          .add(org.jdesktop.layout.GroupLayout.LEADING, weightedCurrentGradeTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
                                          .add(org.jdesktop.layout.GroupLayout.LEADING, weightedRoundTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
                                          .add(weightedCustomGradingButton)
                                          .add(weightedFinalGradeTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)))
                              .add(weightedExitButton))
                        .add(8, 8, 8)
                        .add(weightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                              .add(jLabel2)
                              .add(weightedCurrentGradePercentLabel))
                        .addContainerGap())
            );
            weightedPanelLayout.setVerticalGroup(
                  weightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                  .add(weightedPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(weightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                              .add(weightedCurrentGradeLabel)
                              .add(weightedCurrentGradePercentLabel)
                              .add(weightedCurrentGradeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(weightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                              .add(weightedFinalWorthLabel)
                              .add(jLabel2)
                              .add(weightedFinalWorthTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(11, 11, 11)
                        .add(weightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                              .add(weightedDesiredGradeLabel)
                              .add(weightedDesiredGradeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(weightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                              .add(weightedRoundLabel)
                              .add(weightedRoundTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(weightedStandardGradingRadioButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(weightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                              .add(weightedCustomGradingRadioButton)
                              .add(weightedCustomGradingButton))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(weightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                              .add(weightedFinalGradeLabel)
                              .add(weightedFinalGradeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(weightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                              .add(weightedClearButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 29, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                              .add(weightedCalculateButton))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(weightedExitButton)
                        .add(50, 50, 50))
            );
            jTabbedPane1.addTab("Weighted Course", weightedPanel);

            unweightedCurrentGradeLabel.setText("Your Point Total:");

            unweightedCoursePointsLabel.setText("Course Point Total:");

            unweightedFinalWorthLabel.setText("Final Exam Point Total:");

            unweightedDesiredGradeLabel.setText("Desired Letter Grade in the Course:");

            unweightedRoundLabel.setText("Does the Teacher Round? (y/n):");

            unweightedFinalGradeLabel.setText("Score on Final Needed:");

            unweightedCalculateButton.setText("Calculate");
            unweightedCalculateButton.addActionListener(new java.awt.event.ActionListener()
            {
                  public void actionPerformed(java.awt.event.ActionEvent evt)
                  {
                        unweightedCalculateButtonActionPerformed(evt);
                  }
            });

            unweightedClearButton.setText("Clear");
            unweightedClearButton.addActionListener(new java.awt.event.ActionListener()
            {
                  public void actionPerformed(java.awt.event.ActionEvent evt)
                  {
                        unweightedClearButtonActionPerformed(evt);
                  }
            });

            unweightedExitButton.setText("Exit");
            unweightedExitButton.addActionListener(new java.awt.event.ActionListener()
            {
                  public void actionPerformed(java.awt.event.ActionEvent evt)
                  {
                        unweightedExitButtonActionPerformed(evt);
                  }
            });

            unweightedGradingButtonGroup.add(unweightedStandardGradingRadioButton);
            unweightedStandardGradingRadioButton.setText("Standard Grading Scale");
            unweightedStandardGradingRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
            unweightedStandardGradingRadioButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
            unweightedStandardGradingRadioButton.addActionListener(new java.awt.event.ActionListener()
            {
                  public void actionPerformed(java.awt.event.ActionEvent evt)
                  {
                        unweightedStandardGradingRadioButtonActionPerformed(evt);
                  }
            });

            unweightedGradingButtonGroup.add(unweightedCustomGradingRadioButton);
            unweightedCustomGradingRadioButton.setText("Custom Grading Scale");
            unweightedCustomGradingRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
            unweightedCustomGradingRadioButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
            unweightedCustomGradingRadioButton.addActionListener(new java.awt.event.ActionListener()
            {
                  public void actionPerformed(java.awt.event.ActionEvent evt)
                  {
                        unweightedCustomGradingRadioButtonActionPerformed(evt);
                  }
            });

            unweightedCustomGradingButton.setText("Choose...");
            unweightedCustomGradingButton.addActionListener(new java.awt.event.ActionListener()
            {
                  public void actionPerformed(java.awt.event.ActionEvent evt)
                  {
                        unweightedCustomGradingButtonActionPerformed(evt);
                  }
            });

            org.jdesktop.layout.GroupLayout unweightedPanelLayout = new org.jdesktop.layout.GroupLayout(unweightedPanel);
            unweightedPanel.setLayout(unweightedPanelLayout);
            unweightedPanelLayout.setHorizontalGroup(
                  unweightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                  .add(unweightedPanelLayout.createSequentialGroup()
                        .add(unweightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                              .add(unweightedPanelLayout.createSequentialGroup()
                                    .addContainerGap()
                                    .add(unweightedExitButton))
                              .add(org.jdesktop.layout.GroupLayout.LEADING, unweightedPanelLayout.createSequentialGroup()
                                    .add(17, 17, 17)
                                    .add(unweightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                          .add(org.jdesktop.layout.GroupLayout.LEADING, unweightedPanelLayout.createSequentialGroup()
                                                .add(unweightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                                      .add(unweightedFinalGradeLabel)
                                                      .add(unweightedCurrentGradeLabel)
                                                      .add(unweightedCoursePointsLabel)
                                                      .add(unweightedFinalWorthLabel)
                                                      .add(unweightedRoundLabel)
                                                      .add(unweightedDesiredGradeLabel)
                                                      .add(unweightedStandardGradingRadioButton)
                                                      .add(unweightedCustomGradingRadioButton))
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(unweightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                                      .add(unweightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                                            .add(unweightedRoundTextField)
                                                            .add(unweightedCoursePointsTextField)
                                                            .add(unweightedFinalWorthTextField)
                                                            .add(unweightedDesiredGradeTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)
                                                            .add(unweightedCurrentGradeTextField)
                                                            .add(unweightedCustomGradingButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                                      .add(unweightedFinalGradeTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)))
                                          .add(unweightedPanelLayout.createSequentialGroup()
                                                .add(unweightedCalculateButton)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(unweightedClearButton)))))
                        .addContainerGap(72, Short.MAX_VALUE))
            );
            unweightedPanelLayout.setVerticalGroup(
                  unweightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                  .add(unweightedPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(unweightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                              .add(unweightedCurrentGradeLabel)
                              .add(unweightedCurrentGradeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(unweightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                              .add(unweightedCoursePointsLabel)
                              .add(unweightedCoursePointsTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(unweightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                              .add(unweightedFinalWorthLabel)
                              .add(unweightedFinalWorthTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(unweightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                              .add(unweightedDesiredGradeLabel)
                              .add(unweightedDesiredGradeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(unweightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                              .add(unweightedRoundLabel)
                              .add(unweightedRoundTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(unweightedStandardGradingRadioButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(unweightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                              .add(unweightedCustomGradingRadioButton)
                              .add(unweightedCustomGradingButton))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(unweightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                              .add(unweightedFinalGradeLabel)
                              .add(unweightedFinalGradeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(unweightedPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                              .add(unweightedClearButton)
                              .add(unweightedCalculateButton))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(unweightedExitButton)
                        .add(54, 54, 54))
            );
            jTabbedPane1.addTab("Non-weighted Course", unweightedPanel);

            aboutLabel.setText("<html> Welcome to the Finals Calculator! <br> This program allows you to calculate what you need on your final given your current grade. <br> <br>  Created by Cauchy Choi and Jonathan Chang</html>");

            aboutExitButton.setText("Exit");
            aboutExitButton.addActionListener(new java.awt.event.ActionListener()
            {
                  public void actionPerformed(java.awt.event.ActionEvent evt)
                  {
                        aboutExitButtonActionPerformed(evt);
                  }
            });

            org.jdesktop.layout.GroupLayout aboutPanelLayout = new org.jdesktop.layout.GroupLayout(aboutPanel);
            aboutPanel.setLayout(aboutPanelLayout);
            aboutPanelLayout.setHorizontalGroup(
                  aboutPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                  .add(org.jdesktop.layout.GroupLayout.TRAILING, aboutPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(aboutPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                              .add(org.jdesktop.layout.GroupLayout.LEADING, aboutLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 339, Short.MAX_VALUE)
                              .add(aboutExitButton))
                        .addContainerGap())
            );
            aboutPanelLayout.setVerticalGroup(
                  aboutPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                  .add(aboutPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(aboutLabel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(aboutExitButton)
                        .addContainerGap(189, Short.MAX_VALUE))
            );
            jTabbedPane1.addTab("About", aboutPanel);

            org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                  layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                  .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 364, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                  layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                  .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 327, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
            pack();
      }// </editor-fold>//GEN-END:initComponents

	/**
	 * Called when the "Choose..." button in the Non-Weighted Course tab is clicked.
	 *
	 * @param evt The window event that tells if the "Choose..." button was clicked.
	 */
	private void unweightedCustomGradingButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_unweightedCustomGradingButtonActionPerformed
	{//GEN-HEADEREND:event_unweightedCustomGradingButtonActionPerformed
		//Create new GradingScaleWindow.
		unweightedGradingScaleWindow = new GradingScaleWindow();
		unweightedGradingScaleWindow.setVisible(true);
		unweightedChooseClicked = true;
	}//GEN-LAST:event_unweightedCustomGradingButtonActionPerformed

	/**
	 * Called when the Standard Grading Scale radio button in the Non-Weighted Course tab is clicked.
	 *
	 * @param evt The window event that tells if the Standard Grading Scale radio button was clicked
	 */
	private void unweightedStandardGradingRadioButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_unweightedStandardGradingRadioButtonActionPerformed
	{//GEN-HEADEREND:event_unweightedStandardGradingRadioButtonActionPerformed
		//Set "Choose..." button to be grayed out.
		unweightedCustomGradingButton.setEnabled(false);
	}//GEN-LAST:event_unweightedStandardGradingRadioButtonActionPerformed

	/**
	 * Called when the Custom Grading Scale radio button in the Non-Weighted Course tab is clicked.
	 *
	 * @param evt The window event that tells if the Custom Grading Scale radio button was clicked
	 */
	private void unweightedCustomGradingRadioButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_unweightedCustomGradingRadioButtonActionPerformed
	{//GEN-HEADEREND:event_unweightedCustomGradingRadioButtonActionPerformed
		//Set "Choose..." button to be clickable.
		unweightedCustomGradingButton.setEnabled(true);
	}//GEN-LAST:event_unweightedCustomGradingRadioButtonActionPerformed

	/**
	 * Called when the Standard Grading Scale radio button in the Weighted Course tab is clicked.
	 *
	 * @param evt The window event that tells if the Standard Grading Scale radio button was clicked
	 */
	private void weightedStandardGradingRadioButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_weightedStandardGradingRadioButtonActionPerformed
	{//GEN-HEADEREND:event_weightedStandardGradingRadioButtonActionPerformed
		//Set "Choose..." button to be grayed out.
		weightedCustomGradingButton.setEnabled(false);
	}//GEN-LAST:event_weightedStandardGradingRadioButtonActionPerformed

	/**
	 * Called when the Custom Grading Scale radio button in the Weighted Course tab is selected.
	 *
	 * @param evt The window event that tells if the Custom Grading Scale radio button was clicked.
	 */
	private void weightedCustomGradingRadioButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_weightedCustomGradingRadioButtonActionPerformed
	{//GEN-HEADEREND:event_weightedCustomGradingRadioButtonActionPerformed
		//Set "Choose..." button to be clickable.
		weightedCustomGradingButton.setEnabled(true);
	}//GEN-LAST:event_weightedCustomGradingRadioButtonActionPerformed

	/**
	 * Called when the "Choose..." button in the Weighted Course tab is clicked.
	 *
	 * @param evt The window event that tells if the "Choose..." button was clicked.
	 */
	private void weightedCustomGradingButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_weightedCustomGradingButtonActionPerformed
	{//GEN-HEADEREND:event_weightedCustomGradingButtonActionPerformed
		//Create new GradingScaleWindow.
		weightedGradingScaleWindow = new GradingScaleWindow();
		weightedGradingScaleWindow.setVisible(true);
		weightedChooseClicked = true;
	}//GEN-LAST:event_weightedCustomGradingButtonActionPerformed

	/**
	 * Called when the Exit button in the About tab is clicked.
	 *
	 * @param evt The window event that tells if the Exit button was clicked.
	 */
	private void aboutExitButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_aboutExitButtonActionPerformed
	{//GEN-HEADEREND:event_aboutExitButtonActionPerformed
		//Exit.
		System.exit(0);
	}//GEN-LAST:event_aboutExitButtonActionPerformed

	/**
	 * Called when the Exit button in the Non-weighted Course tab is clicked.
	 *
	 * @param evt The window event that tells if the Exit button was clicked.
	 */
	private void unweightedExitButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_unweightedExitButtonActionPerformed
	{//GEN-HEADEREND:event_unweightedExitButtonActionPerformed
		//Exit.
		System.exit(0);
	}//GEN-LAST:event_unweightedExitButtonActionPerformed

	/**
	 * Called when the Clear button in the Non-weighted Course tab is clicked.
	 *
	 * @param evt The window event that tells if the Clear button was clicked.
	 */
	private void unweightedClearButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_unweightedClearButtonActionPerformed
	{//GEN-HEADEREND:event_unweightedClearButtonActionPerformed
		//Clear all TextFields.
		unweightedCurrentGradeTextField.setText("");
		unweightedCoursePointsTextField.setText("");
		unweightedFinalWorthTextField.setText("");
		unweightedDesiredGradeTextField.setText("");
		unweightedRoundTextField.setText("");
		unweightedFinalGradeTextField.setText("");
	}//GEN-LAST:event_unweightedClearButtonActionPerformed

	/**
	 * Called when the Calculate button in the Non-weighted Course tab is clicked.
	 *
	 * @param evt The window event that tells if the Calculate button was clicked.
	 */
	private void unweightedCalculateButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_unweightedCalculateButtonActionPerformed
	{//GEN-HEADEREND:event_unweightedCalculateButtonActionPerformed
		//Get the user's point total in the course.
		double currentGrade = Double.parseDouble(unweightedCurrentGradeTextField.getText());
		
		//Get the course point total.
		double coursePoints = Double.parseDouble(unweightedCoursePointsTextField.getText());
		
		//Get the final exam point total.
		double finalWorth = Double.parseDouble(unweightedFinalWorthTextField.getText());
		
		//Get the overall grade the user wants in the course.
		String desiredGrade = unweightedDesiredGradeTextField.getText();
		desiredGrade = desiredGrade.trim();
		//desiredGrade = trimLetterGrade(desiredGrade);
		
		//Get if the teacher rounds the overall grade in the course.
		String round = unweightedRoundTextField.getText();
		//If input is not valid, return.
		if (!round.equalsIgnoreCase("y") && !round.equalsIgnoreCase("n"))
		{
			unweightedRoundTextField.setText("");
			return;
		}
		
		//If Standard Grading Scale is chosen
		if (unweightedStandardGradingRadioButton.getSelectedObjects() != null)
		{
			//Create Calculator object to calculate.
			Calculator calculator = new Calculator();

			//Calculate percent grade needed on the final exam.
			double finalGrade = calculator.noWeightStandardGrading(currentGrade, coursePoints, finalWorth, desiredGrade, round);

			//Display results in the window.
			unweightedFinalGradeTextField.setText(String.valueOf(finalGrade) + "%");
		}
		//If Custom Grading Scale is chosen
		else if (unweightedCustomGradingRadioButton.getSelectedObjects() != null)
		{
			//Make sure the GradingScaleWindow isn't null.
			if (!unweightedChooseClicked)
				unweightedGradingScaleWindow = new GradingScaleWindow();
			
			//Create Calculator object to calculate.
			Calculator calculator = new Calculator(unweightedGradingScaleWindow);
			
			//Calculate percent grade needed on the final exam.
			double finalGrade = calculator.noWeightCustomGrading(currentGrade, coursePoints, finalWorth, desiredGrade, round);

			//Display results in the window.
			unweightedFinalGradeTextField.setText(String.valueOf(finalGrade) + "%");
		}
	}//GEN-LAST:event_unweightedCalculateButtonActionPerformed

	/**
	 * Called when the Clear button in the Weighted Course tab is clicked. 
	 *
	 * @param evt The window event that tells if the Exit button was clicked.
	 */
	private void weightedExitButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_weightedExitButtonActionPerformed
	{//GEN-HEADEREND:event_weightedExitButtonActionPerformed
		//Exit.
		System.exit(0);
	}//GEN-LAST:event_weightedExitButtonActionPerformed

	/**
	 * Called when the Clear button in the Weighted Course tab is clicked.
	 *
	 * @param evt The window event that tells if the Clear button was clicked.
	 */
	private void weightedClearButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_weightedClearButtonActionPerformed
	{//GEN-HEADEREND:event_weightedClearButtonActionPerformed
		//Clear all TextFields.
		weightedCurrentGradeTextField.setText("");
		weightedFinalWorthTextField.setText("");
		weightedDesiredGradeTextField.setText("");
		weightedRoundTextField.setText("");
		weightedFinalGradeTextField.setText("");
	}//GEN-LAST:event_weightedClearButtonActionPerformed

	/**
	 * Called when the Calculate button in the Weighted Course tab is clicked.
	 *
	 * @param evt The window event that tells if the Calculate button was clicked.
	 */
	private void weightedCalculateButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_weightedCalculateButtonActionPerformed
	{//GEN-HEADEREND:event_weightedCalculateButtonActionPerformed
		//Get the user's current grade in the course.
		String stringCurrentGrade = weightedCurrentGradeTextField.getText();
		stringCurrentGrade = trimPercent(stringCurrentGrade);
		double currentGrade = Double.parseDouble(stringCurrentGrade) / 100.0;
		
		//Get the weight of the final exam.
		String stringFinalWorth = weightedFinalWorthTextField.getText();
		stringFinalWorth = trimPercent(stringFinalWorth);
		double finalWorth = Double.parseDouble(stringFinalWorth) / 100.0;
		
		//Get the overall grade the user wants in the course.
		String desiredGrade = weightedDesiredGradeTextField.getText();
		//desiredGrade = trimLetterGrade(desiredGrade);
		
		//Get if the teacher rounds the overall grade in the course.
		String round = weightedRoundTextField.getText();
		//If input is not valid, return.
		if (!round.equalsIgnoreCase("y") && !round.equalsIgnoreCase("n"))
		{
			weightedRoundTextField.setText("");
			return;
		}
		
		//If Standard Grading is chosen
		if (weightedStandardGradingRadioButton.getSelectedObjects() != null)
		{
			//Create Calculator object to calculate.
			Calculator calculator = new Calculator();

			//Calculate percent grade needed on the final exam.
			double finalGrade = calculator.weightedStandardGrading(currentGrade, finalWorth, desiredGrade, round);

			//Display results in the window.
			weightedFinalGradeTextField.setText(String.valueOf(finalGrade) + "%");
		}
		//If Custom Grading is chosen
		else if (weightedCustomGradingRadioButton.getSelectedObjects() != null)
		{
			//Make sure the GradingScaleWindow isn't null.
			if (!weightedChooseClicked)
				weightedGradingScaleWindow = new GradingScaleWindow();
			
			//Create Calculator object to calculate.
			Calculator calculator = new Calculator(weightedGradingScaleWindow);
			
			//Calculate percent grade needed on the final exam.
			double finalGrade = calculator.weightedCustomGrading(currentGrade, finalWorth, desiredGrade, round);

			//Display results in the window.
			weightedFinalGradeTextField.setText(String.valueOf(finalGrade) + "%");
		}
	}//GEN-LAST:event_weightedCalculateButtonActionPerformed
	
	/**
	 * Trims a percent to make sure it doesn't have a %
	 *
	 * @param originalPercent The original percent from the <code>jTextField</code>
	 * @return The percent without the %
	 */
	private String trimPercent(String originalPercent)
	{
		//Copy over original percent.
		String trimmedPercent = new String(originalPercent);
		
		//Remove all instances of % in the String.
		trimmedPercent = trimmedPercent.replace('%', ' ');
		trimmedPercent = trimmedPercent.trim();
		
		return trimmedPercent;
	}
	
	
	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[])
	{
		java.awt.EventQueue.invokeLater(new Runnable()
		{
			public void run()
			{
				new CalculatorWindow().setVisible(true);
			}
		});
	}
	
      // Variables declaration - do not modify//GEN-BEGIN:variables
      private javax.swing.JButton aboutExitButton;
      private javax.swing.JLabel aboutLabel;
      private javax.swing.JPanel aboutPanel;
      private javax.swing.JLabel jLabel2;
      private javax.swing.JTabbedPane jTabbedPane1;
      private javax.swing.JButton unweightedCalculateButton;
      private javax.swing.JButton unweightedClearButton;
      private javax.swing.JLabel unweightedCoursePointsLabel;
      private javax.swing.JTextField unweightedCoursePointsTextField;
      private javax.swing.JLabel unweightedCurrentGradeLabel;
      private javax.swing.JTextField unweightedCurrentGradeTextField;
      private javax.swing.JButton unweightedCustomGradingButton;
      private javax.swing.JRadioButton unweightedCustomGradingRadioButton;
      private javax.swing.JLabel unweightedDesiredGradeLabel;
      private javax.swing.JTextField unweightedDesiredGradeTextField;
      private javax.swing.JButton unweightedExitButton;
      private javax.swing.JLabel unweightedFinalGradeLabel;
      private javax.swing.JTextField unweightedFinalGradeTextField;
      private javax.swing.JLabel unweightedFinalWorthLabel;
      private javax.swing.JTextField unweightedFinalWorthTextField;
      private javax.swing.ButtonGroup unweightedGradingButtonGroup;
      private javax.swing.JPanel unweightedPanel;
      private javax.swing.JLabel unweightedRoundLabel;
      private javax.swing.JTextField unweightedRoundTextField;
      private javax.swing.JRadioButton unweightedStandardGradingRadioButton;
      private javax.swing.JButton weightedCalculateButton;
      private javax.swing.JButton weightedClearButton;
      private javax.swing.JLabel weightedCurrentGradeLabel;
      private javax.swing.JLabel weightedCurrentGradePercentLabel;
      private javax.swing.JTextField weightedCurrentGradeTextField;
      private javax.swing.JButton weightedCustomGradingButton;
      private javax.swing.JRadioButton weightedCustomGradingRadioButton;
      private javax.swing.JLabel weightedDesiredGradeLabel;
      private javax.swing.JTextField weightedDesiredGradeTextField;
      private javax.swing.JButton weightedExitButton;
      private javax.swing.JLabel weightedFinalGradeLabel;
      private javax.swing.JTextField weightedFinalGradeTextField;
      private javax.swing.JLabel weightedFinalWorthLabel;
      private javax.swing.JTextField weightedFinalWorthTextField;
      private javax.swing.ButtonGroup weightedGradingButtonGroup;
      private javax.swing.JPanel weightedPanel;
      private javax.swing.JLabel weightedRoundLabel;
      private javax.swing.JTextField weightedRoundTextField;
      private javax.swing.JRadioButton weightedStandardGradingRadioButton;
      // End of variables declaration//GEN-END:variables
	
	private GradingScaleWindow weightedGradingScaleWindow;
	private GradingScaleWindow unweightedGradingScaleWindow;
	private boolean weightedChooseClicked;
	private boolean unweightedChooseClicked;
}